package com.hui.platform.falseworkapi.service.business.webmagic.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.hui.platform.falseworkapi.common.core.vo.PageData;

import com.hui.platform.falseworkapi.service.business.webmagic.bo.TbWebmagicBaiduNewsBO;
import com.hui.platform.falseworkapi.service.business.webmagic.dto.TbWebmagicBaiduNewsDTO;
import com.hui.platform.falseworkapi.service.business.webmagic.convert.TbWebmagicBaiduNewsConvert;

import com.hui.platform.falseworkapi.service.business.webmagic.entity.TbWebmagicBaiduNews;
import com.hui.platform.falseworkapi.service.business.webmagic.mapper.TbWebmagicBaiduNewsMapper;
import com.hui.platform.falseworkapi.service.business.webmagic.service.TbWebmagicBaiduNewsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 爬虫-百度新闻 服务实现类
 *
 * @author hui
 * @since 2020-04-19
 */
@Service
public class TbWebmagicBaiduNewsServiceImpl extends ServiceImpl<TbWebmagicBaiduNewsMapper, TbWebmagicBaiduNews> implements TbWebmagicBaiduNewsService {

    @Override
    public TbWebmagicBaiduNewsBO readById(Long id) {
        return TbWebmagicBaiduNewsConvert.INSTANCE.do2bo(getById(id));
    }

    @Override
    public List<TbWebmagicBaiduNewsBO> readByIds(List<Long> ids) {
        return TbWebmagicBaiduNewsConvert.INSTANCE.do2bo(new ArrayList<>(listByIds(ids)));
    }

    @Override
    public List<TbWebmagicBaiduNewsBO> readList(TbWebmagicBaiduNewsDTO condition) {
        return TbWebmagicBaiduNewsConvert.INSTANCE.do2bo(list(Wrappers.lambdaQuery(TbWebmagicBaiduNewsConvert.INSTANCE.dto2do(condition))));
    }

    @Override
    public PageData<TbWebmagicBaiduNewsBO> readPage(Long pageNum, Long pageSize, TbWebmagicBaiduNewsDTO condition) {
        IPage<TbWebmagicBaiduNews> page = page(new Page<>(pageNum, pageSize), Wrappers.lambdaQuery(TbWebmagicBaiduNewsConvert.INSTANCE.dto2do(condition)));
        return PageData.build(page, TbWebmagicBaiduNewsConvert.INSTANCE.do2bo(page.getRecords()));
    }

    @Override
    public Long createOne(TbWebmagicBaiduNewsDTO dto) {
        TbWebmagicBaiduNews domain = TbWebmagicBaiduNewsConvert.INSTANCE.dto2do(dto);
        return save(domain) ? domain.getId() : null;
    }

    @Override
    public Long updateOne(Long id, TbWebmagicBaiduNewsDTO dto) {
        return updateById(TbWebmagicBaiduNewsConvert.INSTANCE.dto2do(dto).setId(id)) ? id : null;
    }

    @Override
    public Long deleteById(Long id) {
        return removeById(id) ? id : null;
    }

    @Override
    public List<Long> deleteByIds(List<Long> ids) {
        return removeByIds(ids) ? ids : null;
    }

}
